<?php

namespace App\Http\Controllers\System;

use App\Models\System\SysLog;
use App\Http\Controllers\Controller;
use App\Http\Requests\System\Log\ShowLogsRequest;

class LogController extends Controller
{
    public function showLogs(ShowLogsRequest $request)
    {
        $where = array_filter($this->extractInputFromRules($request,$request->rules()));
        $query = SysLog::query();
        if(!empty($where['created_at'])){
            $query->whereBetween('created_at',$where['created_at']);
        }
        if(!empty($where['info'])){
            $query->where('info','like',"%{$where['info']}%");
        }
        if(!empty($where['name'])){
            $query->where('name','like',"%{$where['name']}%");
        }
        $query->orderByDesc('created_at');
        $res = $query->get();
        return success($res);
    }
}
